package com.zsx.shopping.common.api.cart.vo;

import lombok.Data;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.List;

@Data
public class CartVO {

    private List<CartItemVO> items;

    public BigDecimal getTotalAmount() {
        BigDecimal amount = new BigDecimal(0);
        if (!CollectionUtils.isEmpty(items)) {
            for (CartItemVO item : items) {
                amount = amount.add(item.getSubtotal());
            }
        }
        return amount;
    }

    public Integer getTotalCount() {
        Integer count = 0;
        if (!CollectionUtils.isEmpty(items)) {
            for (CartItemVO item : items) {
                count += item.getCount();
            }
        }
        return count;
    }
}
